Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sqrt member to AffineScalarFunc to make numpy.linalg.norm work #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

karlwessel
Copy link

This is my own try at fixing issue #121.

It works by adding sqrt as a member function to AffineScalarFunc so that numpy knows how to calculate the square root of it.

This also makes some other numpy methods work like numpy.sqrt.

@pkienzle
Copy link

The method used here (adding sqrt to the class) will work for many (all?) of the functions in umath, so for example np.sin(ufloat) would return umath.sin(ufloat). Any interest in extending this patch to include all these functions?

The attribute would be needed for both Variable and AffineScalarFunc.

Some methods will need different names, such as arcsin instead of asin.

@karlwessel
Copy link
Author

karlwessel commented Mar 23, 2020

The method used here (adding sqrt to the class) will work for many (all?) of the functions in umath, so for example np.sin(ufloat) would return umath.sin(ufloat). Any interest in extending this patch to include all these functions?

The attribute would be needed for both Variable and AffineScalarFunc.

Some methods will need different names, such as arcsin instead of asin.

During implementation of the patch I already did that for exp but removed it in the end to keep the PR on point (which is just fixing issue #121).

I think once this PR is merged and has proven to work for some time, one could implement your suggestion in a separate PR.

@AndrewAnnex
Copy link

I can see that some time has past since this pr was last updated, and I just ran into this issue (plus the norm one) when attempting to use uncertainties with statsmodels. Are the failed checks related to an incomplete implementation? If this works as-is I can make progress on my own work by just monkey-patching

@AndrewAnnex
Copy link

I also see an issue where numpy needs an implementation of the conjugate method as the default in numpy is to use the Frobenius norm, although this is really not my area

@jagerber48
Copy link
Contributor

My rewrite, discussed in #251 implements sqrt on UFloat and so would cover this PR and associated issue. In that rewrite the np.linalg.norm functions work on a dtype=object ndarray of UFloat objects, or on the UArray object (thin wrapper for dtype=object ndarray of UFloat).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants